package com.university.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.university.mapper.UserMapper;
import com.university.pojo.entity.User;
import com.university.service.UserService;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Date: 2021/5/13 0:04
 * @Description:
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    @SneakyThrows
    public User login(String username, String password) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(User::getUsername, username);
        User user = userMapper.selectOne(wrapper);
        if (user == null) {
            throw new Exception("用户名输入错误！");
        }
        if (!password.equals(user.getPassword())) {
            throw new Exception("密码输入错误！");
        }
        return user;
    }

}
